package org.tissou.server.Services;

import org.tissou.client.Services.MonException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 * User: Manu
 * Date: 9 juin 2009
 * Time: 08:21:24
 * To change this template use File | Settings | File Templates.
 */
public class UltraSimpleServlet extends HttpServlet {

  public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String quoi = request.getParameter("quoi");
    String qui = request.getParameter("qui");
    float somme = 0;
    String avecQui = request.getParameter("avecqui");
    String nomCompte = request.getParameter("compte");

//    if (quoi == null || quoi.equals("") || qui == null || qui.equals("")) {
//      response.getWriter().write("Pas top top");
//    }
    try {
      try {
        somme = Float.valueOf(request.getParameter("somme"));
      } catch (NullPointerException e) {
        throw new MonException("Mauvaise somme");
      } catch (NumberFormatException e) {
        throw new MonException("Mauvaise somme");
      }
      new UltraSimpleTransactionServiceImpl().entrerTransaction(qui, nomCompte, quoi, somme, avecQui, 0.5f);
      response.getWriter().write("ok");
    } catch (MonException e) {
      response.getWriter().write(e.getLocalizedMessage());
    }
  }

}
